package com.lovestacks.tj.service;

import com.lovestacks.tj.bean.PersonInfomation;
import com.lovestacks.tj.dao.PersonInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterService {
    @Autowired
    private PersonInfoDao personInfoDao;
    public void insertRegisterInfo(String openId,String name,String phone,String depart,String menu){
        PersonInfomation personInfomation = new PersonInfomation();
        personInfomation.setOpenId(openId);
        personInfomation.setName(name);
        personInfomation.setPhone(phone);
        personInfomation.setDepart(depart);
        personInfomation.setMenu(menu);

        synchronized(this)    /*同步函数的锁*/
        {
            int num = personInfoDao.getPersonInfoNum(personInfomation);
            if (num == 0){
                personInfoDao.insertPersonInfo(personInfomation);
            }else {
                personInfoDao.updatePersonInfo(personInfomation);
            }
        }

    }
    public PersonInfomation getInfo(String id){
        PersonInfomation result = personInfoDao.getPersonInfo(id);
        return result;
    }
}
